set more off

*** memphis ***

use "dataset_memphis wave 1", clear

foreach x in ideoawg ideocoll ideohodges ideowalk ideowebb ideowilliams {
	replace `x' = 4 if mi(`x')
}

gen ideononstrickland = (ideoawg + ideocoll + ideohodges + ideowalk + ideowebb + ideowilliams)/6
gen spatialadvantage = (abs(ideoawg -ideoself) + abs(ideocoll -ideoself) + abs(ideohodges -ideoself)+ abs(ideowalk -ideoself)+ abs(ideowebb-ideoself) + abs(ideowilliams-ideoself))/6 - abs(ideostrickland - ideoself) 

#delimit

gr tw 
	(lpolyci votestrick spatialadvantage, clcol(black))
	,
		legend(off)
		ytitle("Proportion voting for Strickland")
		plotregion(style(none))
		xtitle("Strickland's relative spatial advantage")
		ylab(0(.2)1, angle(horiz))
		title("(a) Memphis")		
		;

#delimit cr

gr export "figure A6 a.eps", replace
shell epstopdf "figure A6 a.eps"

*** nashville ***

use "dataset_nashville wave 1", clear

foreach x in kane bone rebrovick freeman fox gentry {
	replace ideo`x'1 = 4 if mi(ideo`x'1)
}
gen ideononbarry = (ideokane1 + ideobone1 + ideorebrovick1 + ideofreeman1 + ideofox1 + ideogentry1)/6 
gen spatialadvantage = (abs(ideokane1-ideoself1) + abs(ideobone1-ideoself1) + abs(ideorebrovick1 - ideoself1) + abs(ideofreeman1-ideoself1) + abs(ideofox1-ideoself1) + abs(ideogentry1-ideoself1))/6 - abs(ideobarry1- ideoself1) 

#delimit

gr tw 
	(lpolyci votebarry1 spatialadvantage, clcol(black))
	,
		legend(off)
		ytitle("Proportion voting for Barry")
		plotregion(style(none))
		xtitle("Barry's relative spatial advantage")
		ylab(0(.2)1, angle(horiz))
		title("(b) Nashville")
		;

#delimit cr

gr export "figure A6 b.eps", replace
shell epstopdf "figure A6 b.eps"

*** nashville panel ***

use "dataset_nashville panel", clear

foreach x in kane bone rebrovick freeman fox gentry {
	replace ideo`x'1 = 4 if mi(ideo`x'1)
	replace ideo`x'2 = 4 if mi(ideo`x'2)
}
gen ideononbarry1 = (ideokane1 + ideobone1 + ideorebrovick1 + ideofreeman1 + ideofox1 + ideogentry1)/6 
gen ideononbarry2 = (ideokane2 + ideobone2 + ideorebrovick2 + ideofreeman2 + ideofox2 + ideogentry2)/6 
gen spatialadvantage1 = (abs(ideokane1-ideoself1) + abs(ideobone1-ideoself1) + abs(ideorebrovick1 - ideoself1) + abs(ideofreeman1-ideoself1) + abs(ideofox1-ideoself1) + abs(ideogentry1-ideoself1))/6 - abs(ideobarry1- ideoself1) 
gen spatialadvantage2 = (abs(ideokane2-ideoself2) + abs(ideobone2-ideoself2) + abs(ideorebrovick2 - ideoself2) + abs(ideofreeman2-ideoself2) + abs(ideofox2-ideoself2) + abs(ideogentry2-ideoself2))/6 - abs(ideobarry2- ideoself2) 

gen dspat = spatialadvantage2 - spatialadvantage1

#delimit

gr tw 
	(lpolyci votebarry2 dspat, clcol(black))
	,
		legend(off)
		ytitle("Proportion voting for Barry in wave 2")
		plotregion(style(none))
		xtitle("Change in Barry's spatial advantage")
		ylab(0(.2)1, angle(horiz))
		title("(c) Nashville panel")
		;

#delimit cr

gr export "figure A6 c.eps", replace
shell epstopdf "figure A6 c.eps"
